﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WebResult : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IWebResult
    {
        #region Public Members

        #region ContentLength

        private System.Nullable<long> _ContentLength;
        partial void OnBeforeContentLengthPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterContentLengthPropertyChanged();
        public System.Nullable<long> ContentLength
        { 
            get
            {
                return _ContentLength;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ContentLength = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _ContentLength);
                    OnBeforeContentLengthPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ContentLength", eventData.Value, true, true);
                        OnAfterContentLengthPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ResponseTime

        private System.Nullable<System.TimeSpan> _ResponseTime;
        partial void OnBeforeResponseTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterResponseTimePropertyChanged();
        public System.Nullable<System.TimeSpan> ResponseTime
        { 
            get
            {
                return _ResponseTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ResponseTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _ResponseTime);
                    OnBeforeResponseTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ResponseTime", eventData.Value, true, true);
                        OnAfterResponseTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region StatusCode

        private System.Nullable<global::System.Net.HttpStatusCode> _StatusCode;
        partial void OnBeforeStatusCodePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData);
        partial void OnAfterStatusCodePropertyChanged();
        public System.Nullable<global::System.Net.HttpStatusCode> StatusCode
        { 
            get
            {
                return _StatusCode;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _StatusCode = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>>(value, _StatusCode);
                    OnBeforeStatusCodePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("StatusCode", eventData.Value, true, true);
                        OnAfterStatusCodePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WebAddress

        private string _WebAddress;
        partial void OnBeforeWebAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterWebAddressPropertyChanged();
        public string WebAddress
        { 
            get
            {
                return _WebAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WebAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _WebAddress);
                    OnBeforeWebAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WebAddress", eventData.Value, true, true);
                        OnAfterWebAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WebExecutionContextId

        private int _WebExecutionContextId;
        partial void OnBeforeWebExecutionContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterWebExecutionContextIdPropertyChanged();
        public int WebExecutionContextId
        { 
            get
            {
                return _WebExecutionContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WebExecutionContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _WebExecutionContextId);
                    OnBeforeWebExecutionContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WebExecutionContextId", eventData.Value, true, true);
                        OnAfterWebExecutionContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WebTargetId

        private System.Nullable<int> _WebTargetId;
        partial void OnBeforeWebTargetIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterWebTargetIdPropertyChanged();
        public System.Nullable<int> WebTargetId
        { 
            get
            {
                return _WebTargetId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WebTargetId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _WebTargetId);
                    OnBeforeWebTargetIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WebTargetId", eventData.Value, true, true);
                        OnAfterWebTargetIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public WebExecutionContext WebExecutionContext { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public WebResult Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Copy(this);
        }
        public WebResult Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWebResult item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWebResult item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Initialize(this, settings);
        }

        #endregion

        #region IWebResult Members

        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IWebResult.ContentLength
        {
            get
            {
                return this._ContentLength;
            }
            set
            {
                this._ContentLength = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IWebResult.ResponseTime
        {
            get
            {
                return this._ResponseTime;
            }
            set
            {
                this._ResponseTime = value;
            }
        }
        System.Nullable<global::System.Net.HttpStatusCode> global::Sidvall.WorkItemManager.Data.IWebResult.StatusCode
        {
            get
            {
                return this._StatusCode;
            }
            set
            {
                this._StatusCode = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWebResult.WebAddress
        {
            get
            {
                return this._WebAddress;
            }
            set
            {
                this._WebAddress = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IWebResult.WebExecutionContextId
        {
            get
            {
                return this._WebExecutionContextId;
            }
            set
            {
                this._WebExecutionContextId = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IWebResult.WebTargetId
        {
            get
            {
                return this._WebTargetId;
            }
            set
            {
                this._WebTargetId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWebExecutionContext global::Sidvall.WorkItemManager.Data.IWebResult.WebExecutionContext
        {
            get
            {
                return this.WebExecutionContext;
            }
            set
            {
                this.WebExecutionContext = (WebExecutionContext)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WebResult()
        {
        }
        public WebResult(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public WebResult(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WebResultManager.Initialize(this);
        }

        #endregion
    }
}